home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Applications / Argus TE 2.0 / TE Window / TE Window.cp next >
Encoding:
Text File  |  1995-06-28  |  7.0 KB  |  278 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  
  3.     TE Window.c
  4.  
  5. ***********************************************************************/
  6.  
  7. #include <stdlib.h>
  8. #include "Fn_Prototypes.h"
  9.  
  10. #define DRAG_THRESHOLD 30
  11. #define INSET          3
  12.  
  13. extern gNewWindowLeft;
  14. extern gNewWindowTop;
  15. extern TEHandle gTEH;
  16. extern ControlHandle gSBH;
  17. extern Boolean gDirty;
  18. extern Boolean gSaved;
  19. extern Str255 gFilename;
  20. extern WindowPtr gWindow;
  21. extern short gVRef;
  22. extern short gRefNum;
  23. extern THPrint gPrintH;
  24.  
  25. extern void FnIO_pStrCopy( StringPtr p1, StringPtr p2 );
  26.  
  27.  
  28. struct WindowData
  29. {
  30.     TEHandle      wTEH;
  31.     ControlHandle wSBH;
  32.     Boolean       wDirty;
  33.     Boolean       wSaved;
  34.     Str255        wFilename;
  35.     short         wVRef;
  36.     short         wRefNum;
  37.     THPrint       wPrintH;
  38. };
  39.  
  40. /********** Prototypes */
  41. void MyCreateWindow(       short       winID,
  42.                            Ptr         winRec,
  43.                            WindowPtr   behind,
  44.                            int         top,
  45.                            int         left,
  46.                            int         offset,
  47.                            int         errID );
  48. void MyCreateHiddenWindow( short       winID,
  49.                            Ptr         winRec,
  50.                            WindowPtr   behind,
  51.                            int         top,
  52.                            int         left,
  53.                            int         offset,
  54.                            int         errID );
  55. void MyDoContent(          WindowPtr   w,
  56.                            EventRecord *e );
  57. void MyDoUpdateWindow(     WindowPtr   w );
  58. void MyDoActivateWindow(   WindowPtr   w );
  59. void MyDoDeactivateWindow( WindowPtr   w );
  60. void MyDoGrow(             WindowPtr   w, 
  61.                            Point       clickLoc );
  62.  
  63. /********** CreateWindow */
  64.  
  65. void MyCreateWindow( short     winID,
  66.                      Ptr       winRec,
  67.                      WindowPtr behind,
  68.                      int       top,
  69.                      int       left,
  70.                      int       offset,
  71.                      int       errID )
  72. {
  73.     WindowPtr         w;
  74.     ControlHandle     c;
  75.     struct WindowData *wd;
  76.     Str255            wTitle = "\pUntitled";
  77.     Str255            tempFilename = "\p";
  78.     
  79.     if ( ( w = GetNewWindow( winID, winRec, behind ) ) == nil )
  80.         FnErr_DisplayStrID( errID, TRUE );
  81.     if (((screenBits.bounds.right - gNewWindowLeft) < DRAG_THRESHOLD) ||
  82.         ((screenBits.bounds.bottom - gNewWindowTop) < DRAG_THRESHOLD))
  83.     {
  84.         gNewWindowLeft = left;
  85.         gNewWindowTop = top;
  86.     }
  87.     
  88.     MoveWindow( w, gNewWindowLeft, gNewWindowTop, FALSE );
  89.     gNewWindowLeft += offset;
  90.     gNewWindowTop += offset;
  91.     
  92.     FnTE_SetUpTEWindow( w,         // window ptr
  93.                         TRUE,      // hasGrowIcon
  94.                         TRUE,      // wordWrap
  95.                         monaco,    // font
  96.                         9,         // textSize
  97.                         INSET,     // textInsetPixels
  98.                         &gTEH,     // *te (result)
  99.                         &gSBH );   // *vScroll (result)
  100.  
  101.     // store reference to TE and scroll bar in window record
  102.     wd = (struct WindowData *)malloc(sizeof(struct WindowData));
  103.     wd->wTEH = gTEH;
  104.     wd->wSBH = gSBH;
  105.     wd->wDirty = 0;
  106.     wd->wSaved = 0;
  107.     wd->wVRef = 0;
  108.     wd->wRefNum = 0;
  109.     wd->wPrintH = NULL;
  110.     FnIO_pStrCopy( wTitle, wd->wFilename );
  111.     SetWRefCon(w,(long)wd);
  112.     
  113.     // set global values
  114.     gDirty = 0;
  115.     gSaved = 0;
  116.     FnIO_pStrCopy( tempFilename, gFilename );
  117.     gWindow = w;
  118.     gVRef = 0;
  119.     gRefNum = 0;
  120.     
  121.     SetWTitle(w,wTitle);
  122.  
  123.     ShowWindow( w );
  124.     DrawControls( w );
  125. }
  126.  
  127.  
  128. /********** DoContent */
  129.  
  130. void MyDoContent( WindowPtr w, EventRecord *e )
  131. {
  132.     struct WindowData *wd;
  133.  
  134.     wd = (struct WindowData *)GetWRefCon(w);
  135.     FnTE_DoContent(
  136.         w,
  137.         e,
  138.         &(wd->wTEH),
  139.         &(wd->wSBH) );
  140. }
  141.  
  142.  
  143. /********** MyDoUpdateWindow */
  144.  
  145. void MyDoUpdateWindow( WindowPtr w )
  146. {
  147.     struct WindowData *wd;
  148.  
  149.     wd = (struct WindowData *)GetWRefCon(w);
  150.     FnTE_UpdateWindow( 
  151.         w,
  152.         &(wd->wTEH),
  153.         TRUE );
  154. }
  155.  
  156.  
  157. /********** MyDoActivateWindow */
  158.  
  159. void MyDoActivateWindow( WindowPtr w )
  160. {
  161.     struct WindowData *wd;
  162.  
  163.     // set globals
  164.     wd = (struct WindowData *)GetWRefCon(w);
  165.     gTEH = wd->wTEH;
  166.     gSBH = wd->wSBH;
  167.     gDirty = wd->wDirty;
  168.     gSaved = wd->wSaved;
  169.     FnIO_pStrCopy( wd->wFilename, gFilename );
  170.     gWindow = w;
  171.  
  172.     FnTE_DoActivate(
  173.         w,
  174.         &(wd->wTEH),
  175.         &(wd->wSBH),
  176.         TRUE,
  177.         TRUE );
  178. }
  179.  
  180.  
  181. /********** MyDoDeactivateWindow */
  182.  
  183. void MyDoDeactivateWindow( WindowPtr w )
  184. {
  185.     struct WindowData *wd;
  186.  
  187.     wd = (struct WindowData *)GetWRefCon(w);
  188.     FnTE_DoActivate(
  189.         w,
  190.         &(wd->wTEH),
  191.         &(wd->wSBH), 
  192.         TRUE,
  193.         FALSE );
  194. }
  195.  
  196.  
  197. /********** MyDoGrow */
  198.  
  199. void MyDoGrow( WindowPtr w, Point clickLoc)
  200. {
  201.     struct WindowData *wd;
  202.  
  203.     wd = (struct WindowData *)GetWRefCon(w);
  204.     FnTE_GrowWindow(
  205.         w,
  206.         &(wd->wTEH),
  207.         &(wd->wSBH), 
  208.         INSET,
  209.         clickLoc );
  210. }
  211.  
  212.  
  213. /********** CreateWindow */
  214.  
  215. void MyCreateHiddenWindow( short     winID,
  216.                           Ptr       winRec,
  217.                           WindowPtr behind,
  218.                           int       top,
  219.                           int       left,
  220.                           int       offset,
  221.                           int       errID )
  222. // Same as CreateWindow except for commented out lines
  223. {
  224.     WindowPtr         w;
  225.     ControlHandle     c;
  226.     struct WindowData *wd;
  227.     Str255            wTitle = "\pUntitled";
  228.     Str255            tempFilename = "\p";
  229.     
  230.     if ( ( w = GetNewWindow( winID, winRec, behind ) ) == nil )
  231.         FnErr_DisplayStrID( errID, TRUE );
  232.     if (((screenBits.bounds.right - gNewWindowLeft) < DRAG_THRESHOLD) ||
  233.         ((screenBits.bounds.bottom - gNewWindowTop) < DRAG_THRESHOLD))
  234.     {
  235.         gNewWindowLeft = left;
  236.         gNewWindowTop = top;
  237.     }
  238.     
  239.     MoveWindow( w, gNewWindowLeft, gNewWindowTop, FALSE );
  240.     gNewWindowLeft += offset;
  241.     gNewWindowTop += offset;
  242.     
  243.     FnTE_SetUpTEWindow( w,         // window ptr
  244.                         TRUE,      // hasGrowIcon
  245.                         TRUE,      // wordWrap
  246.                         monaco,    // font
  247.                         9,         // textSize
  248.                         INSET,     // textInsetPixels
  249.                         &gTEH,     // *te (result)
  250.                         &gSBH );   // *vScroll (result)
  251.  
  252.     // store reference to TE and scroll bar in window record
  253.     wd = (struct WindowData *)malloc(sizeof(struct WindowData));
  254.     wd->wTEH = gTEH;
  255.     wd->wSBH = gSBH;
  256.     wd->wDirty = 0;
  257.     wd->wSaved = 0;
  258.     wd->wVRef = 0;
  259.     wd->wRefNum = 0;
  260.     wd->wPrintH = NULL;
  261.     FnIO_pStrCopy( wTitle, wd->wFilename );
  262.     SetWRefCon(w,(long)wd);
  263.     
  264.     // set global values
  265.     gDirty = 0;
  266.     gSaved = 0;
  267.     FnIO_pStrCopy( tempFilename, gFilename );
  268.     gWindow = w;
  269.     gVRef = 0;
  270.     gRefNum = 0;
  271.     
  272.     SetWTitle(w,wTitle);
  273.  
  274.     //ShowWindow( w );
  275.     //DrawControls( w );
  276. }
  277.  
  278. // End of File